package com.tai.reflect;

import com.tai.java8.Student;
import org.junit.Test;

import java.io.PrintStream;
import java.lang.reflect.Method;

/**
 * The type Reflect test.
 *
 * @Desc : 反射练习
 * @Author ： taylor
 * @Date ：2021/10/31 10:00
 */
public class ReflectTest {

    /**
     * Test.
     *
     * @throws IllegalAccessException the illegal access exception
     * @throws InstantiationException the instantiation exception
     */
    @Test
    public void test() throws IllegalAccessException, InstantiationException {
        Class<StringBuffer> clazz = StringBuffer.class;

        Method[] declaredMethods = clazz.getDeclaredMethods();
        for (Method declaredMethod : declaredMethods) {
            System.out.println("StringBuffer的全部方法："+declaredMethod);
        }

        Method[] methods = clazz.getMethods();
        for (Method method : methods) {
            System.out.println("StringBuffer的public的方法："+method);
        }

        StringBuffer stringBuffer = clazz.newInstance();
        stringBuffer.append("abcd");

    }

    /**
     * Test 1.
     */
    @Test
    public void test1(){
//        ClassLoader classLoader = StringBuilder.class.getClassLoader();

        ClassLoader classLoader = Student.class.getClassLoader();
        System.out.println(classLoader);
        System.out.println(classLoader.getParent());
        System.out.println(classLoader.getParent().getParent());

    }
}
